/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.uba.fi.RSACryptoFiuba.view.commons;

import java.awt.Font;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;

@SuppressWarnings("serial")
public class LearningInteractionPanel extends JPanel {

	private String operation;
	private String description;
	private JLabel descriptionLabel;
    private JPanel descriptionPanel;
    private JLabel operationLabel;
    private JPanel operationPanel;
    private JTextField operationValue;
	
    public LearningInteractionPanel(String operation, String description) {
    	this.operation = operation;
    	this.description = description;
        initComponents();
    }
                         
    private void initComponents() {

        descriptionPanel = new JPanel();
        descriptionLabel = new JLabel();
        operationPanel = new JPanel();
        operationValue = new JTextField();
        operationLabel = new JLabel();
        
        operationValue.setBackground(getBackground());
        operationValue.addKeyListener(new NavigableKeyActionListener());

        descriptionLabel.setText(description);
        descriptionLabel.setVerticalAlignment(SwingConstants.TOP);

        GroupLayout descriptionPanelLayout = new GroupLayout(descriptionPanel);
        descriptionPanel.setLayout(descriptionPanelLayout);
        descriptionPanelLayout.setHorizontalGroup(
            descriptionPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(descriptionLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );
        descriptionPanelLayout.setVerticalGroup(
            descriptionPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(descriptionLabel, GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                .addContainerGap())
        );

        operationLabel.setFont(new Font("Ubuntu", 1, 18));
        operationLabel.setText(operation);
        
        operationValue.setFont(new Font("Ubuntu", 1, 18));

        GroupLayout operationPanelLayout = new GroupLayout(operationPanel);
        operationPanel.setLayout(operationPanelLayout);
        operationPanelLayout.setHorizontalGroup(
            operationPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(Alignment.TRAILING, operationPanelLayout.createSequentialGroup()
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(operationPanelLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(operationLabel)
                    .addComponent(operationValue, GroupLayout.PREFERRED_SIZE, 255, GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );
        operationPanelLayout.setVerticalGroup(
            operationPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(operationPanelLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(operationLabel)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(operationValue, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(descriptionPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(operationPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addComponent(descriptionPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(operationPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }                
    
    public void setOperationValue(String value){
    	this.operationValue.setText(value);
    }
                       
}

